import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.joda.time.DateTime;

import java.util.Date;

public class ExcelPoiUtils {


    public String getValue(Cell thiscell){
        String cellValue="";
        int cellType = thiscell.getCellType();

        switch (cellType){
            case XSSFCell.CELL_TYPE_STRING://字符串
//                System.out.print("[STRING]");
                cellValue = thiscell.getStringCellValue();
                break;
            case XSSFCell.CELL_TYPE_BOOLEAN://布尔
//                System.out.print("[BOOLEAN]");
                cellValue = String.valueOf(thiscell.getBooleanCellValue());
                break;
            case XSSFCell.CELL_TYPE_BLANK://空
                System.out.print("[BLANK]");
                break;
            case XSSFCell.CELL_TYPE_NUMERIC://数字（日期、普通数字）
//                System.out.print("[NUMERIC]");
                if (HSSFDateUtil.isCellDateFormatted(thiscell)){
//                    System.out.print("[日期]");
                    Date date = thiscell.getDateCellValue();
                    cellValue = new DateTime(date).toString("yyyy-MM-dd HH:mm:ss");
                }else{
//                    System.out.print("[转换成字符串输出]");
                    thiscell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cellValue = thiscell.toString();
                }
                break;
            case XSSFCell.CELL_TYPE_ERROR:
                System.out.print("[数据类型错误]");
                break;
        }
        return cellValue;
    }

}
